<!DOCTYPE html>
<html lang="en-us" id="extr-page">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../global/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
    <link rel="stylesheet" href="../../global/css/ztree/demo.css" type="text/css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form" enctype="multipart/form-data">
        <fieldset>
            <input type="hidden" id="goodsId" name="goodsId">
            <div class="form-group">
                <label class="col-md-2 control-label">商品名称:</label>
                <div class="col-md-10">
                    <input class="form-control" placeholder="商品名称" type="text" name="goodsName" id="goodsName"
                           data-bv-notempty="true"
                           data-bv-notempty-message="商品名称不能为空">
                </div>
            </div>

          <div class="form-group">
                  <label class="col-md-2 control-label">所属店铺:</label>
                  <div class="col-md-10" style="width: 160px">
                  <select class="form-control input-sm" name="shopsId" id="shopsId">
                  </select>
                  </div>
                  </div>
         <div class="form-group">
                    <label class="col-md-2 control-label">原价:</label>
                    <div class="col-md-10">
                     <input class="form-control" placeholder="原价" type="text" name="originalPrice" id="originalPrice"/>
                    </div>
                   </div>
         <div class="form-group">
                     <label class="col-md-2 control-label">现价:</label>
                     <div class="col-md-5">
                      <input class="form-control" placeholder="现价" type="text" name="presentPrice" id="presentPrice"/>
                     </div>
                    </div>
         <div class="form-group">
                    <label class="col-md-2 control-label">图片:</label>
                    <div class="col-md-10">
                    <img id="pic" />
                    <input type="file" name="pic" id="pic" />
                    </div>
                    </div>
         <div class="form-group">
                    <label class="col-md-2 control-label">商品banner:</label>
                    <div class="col-md-10">
                    <img id="Banner" />
                    <input type="file" name="Banner" id="Banner" />
                    </div>
                    </div>
             <div class="form-group">
                            <label class="col-md-2 control-label">状态:</label>
                            <div class="col-md-10" style="width: 120px">
                             <select class="form-control input-sm" name="status" id="status">
                             <option value="0" >正常</option>
                             <option value="1" selected="selected">禁止</option> </select>
                        </div>
                        </div>
            <div class="form-group">
                   <label class="col-md-2 control-label">销量:</label>
                   <div class="col-md-5">
                   <input class="form-control" placeholder="销量" type="text" name="salesVolume" id="salesVolume"  />
                   </div>
                   </div>

            <div class="form-group">
                    <label class="col-md-2 control-label">商品类型:</label>
                    <div class="col-md-10" style="width: 160px">
                     <select class="form-control input-sm" name="goodsType" id="goodsType">
                      </select>
                      </div>
                      </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='shopgoods大萨达所List.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="add()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>

<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../global/js/common.js"></script>
<script type="text/javascript" src="../../global/layui/layui.js"></script>
<script type="text/javascript" src="../../global/js/my/roles/role.js"></script>
<script type="text/javascript" src="../../global/js/ajaxfileupload.js"></script>
<script type="text/javascript">
    $(function () {
        $.ajax({
            url: "/clyjNearbyShops/getshops",
            dataType: 'json',
            type: 'post',
            async: false,
            success: function (data) {
                $.each(data, function (index, data) {
                    $("#shopsId").append("<option value='" + data.shopsId + "'>" + data.shopsName + "</option>");
                });
            }
        })
            $.ajax({
                url: "/clyjNearbyGoodsType/getType",
                dataType: 'json',
                type: 'post',
                async: false,
                success: function (data) {
                    $.each(data, function (index, data) {
                        $("#goodsType").append("<option  value='" + data.id + "'>" + data.name + "</option>");
                    });
                }
            })
              layui.use('layer', function () {
                    var layer = layui.layer;
                });

                initData();
        })



    function initData() {
        var id = getUrlParam("id");
        if (id != "") {
            $.ajax({
                type: 'get',
                url: '/clyjNearbyShopsGoods/' + id,
                async: false,
                success: function (result) {
                    var data = result.data;
                    $("#goodsId").val(data.goodsId);
                    $("#goodsName").val(data.goodsName);
                    $("#shopsId").val(data.shopsId);
                    $("#originalPrice").val(data.originalPrice);
                    $("#presentPrice").val(data.presentPrice);
                    $("#pic").attr("src",data.picture);
                    $("#Banner").attr("src",data.goodsBanner);
                    $("#status").val(data.status);
                    $("#salesVolume").val(data.salesVolume);
                    $("#goodsType").val(data.goodsType);
                }
            });

        }
    }
    $('#form').bootstrapValidator();

    function add() {
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }
     $("form").ajaxSubmit({
                type: 'post',
                url: '/clyjNearbyShopsGoods/saveShopsGoods',
                traditional: true,
                contentType: "application/json; charset=utf-8",
                //data: JSON.stringify(formdata),
                success: function (data) {
                    layer.msg("修改成功", {shift: -1, time: 1000}, function () {
                        location.href = "shopgoods大萨达List.html";
                    });
                }
            });
        }

</script>

</body>
</html>